package ru.infosystem.client.model;

import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;
import ru.infosystem.client.data.Group;

/**
 *
 * @author akoshi
 */

public class GroupTableModel extends AbstractTableModel  {
    
    private final int columnsNumber = 2;
    
    private final String[] columnsNames = {
        "Group Number","Faculty",
    };
    
    private  ArrayList<String[]>  resultSets;
    
    public GroupTableModel(Group[] groups) {
      
        resultSets = new ArrayList<String[]>();  
    
        try {
          
            for(Group gr : groups) {

                String[] row = {
                    Integer.toString(gr.getGroupNumber()),
                    gr.getFaculty()
                };

                resultSets.add(row);
            }
           
        } catch(Exception e) {           
            System.out.println("Exception in StudentTableModel");
        }
    }

    @Override
    public Object getValueAt(int rowindex, int columnindex) {
        
       String[] row = resultSets.get(rowindex);
       
       return row[columnindex];
        
    }
    
    @Override
    public int getRowCount() {
        return resultSets.size();
    }
    
    @Override
    public int getColumnCount() {
        return columnsNumber;
    }
    
    @Override
    public String getColumnName( int param ) {

       return columnsNames[param];
    } 
    
}
